/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) {
        vector<int> ans1,ans2;
        ans1=layerorder(p);
        ans2=layerorder(q);
        return ans1==ans2;
    }
    vector<int> layerorder(TreeNode*p){
        vector<int> res;
        queue<TreeNode*> que;
        TreeNode* tmp;
        que.push(p);
        while(!que.empty()){
            tmp=que.front();
            que.pop();
            if(tmp==nullptr){res.push_back(-999);continue;}
            else{res.push_back(tmp->val);}
            que.push(tmp->left);
            que.push(tmp->right);
        }
        return res;
    }
};